<template>
	<view class="page">
		<!-- #ifndef MP-WEIXIN-->
		<my-navbar leftText="差额流水"  @leftClick="back" ></my-navbar>
		<!-- #endif -->
		<view class="content">
			<view class="list" v-for="item in dataList" :key="item.id" @click="toDetail(item.id)">
				<view class="left">
					<view>流水类型：{{item.typeName}}</view>
					<view>流水时间：<text style="color:#9A9A9A">{{item.createdTime}}</text></view>
				</view>
				<view class="right flex-btw">
					<view>
						<view class="status">
							状态：
							<text v-if="item.status==2" style="color:#19be6b">正常</text>
							<text v-else-if="item.status==1" style="color:#ff9900">确认中</text>
							<text v-else-if="item.status==0" style="color:#c8c9cc">已关闭</text>
						</view>
						<view>金额：<text style="color:#E84B4B">￥{{item.balance_change}}</text></view>						
					</view>
					<u-icon name="arrow-right"></u-icon>					
				</view>
			</view>
			<view class="nodata" v-if="dataList.length==0">
				<image :src="nodataImg" mode="aspectFit"></image>
				<view>空空如也~</view>
			</view>
		</view>
	</view>
</template>

<script>
	import {$https} from '@/static/js/request.js';
	export default {
		data() {
			return {
				nodataImg:getApp().globalData.nodataImg,
				dataList:[],
				count:null,
				page:1,
				flag:false,
			};
		},
		onLoad(){
			this.getData(1);
		},
		onShow(){
			uni.$once('updatebalance',res=>{
				this.flag = true;
			})
			if(this.flag){
				this.getData(1);
			}
			this.flag = false;
		},
		methods:{
			getData(page){
				var params = {
					size:20,
					page,
				}
				$https('GET','getBalanceWater',params,res=>{
					if(res.data.errcode==0){
						var list = res.data.data.list;
						for(let i in list){
							switch(list[i].type){
								case 0:{list[i].typeName = '平台多退';break;};
								case 1:{list[i].typeName = '平台欠收';break;};
								case 2:{list[i].typeName = '自主少补';break;};
								case 3:{list[i].typeName = '自主抵扣';break;};
								case 4:{list[i].typeName = '平台结清';break;};
								case 5:{list[i].typeName = '自主结清';break;};
								case 6:{list[i].typeName = '平台退款';break;};
							}
							var ms = Number(list[i].created_at+'000');
							var now = new Date();
							now.setTime(ms);
							var date = now.getFullYear()+"-" + (now.getMonth()+1) + "-" + now.getDate()+ ' ' + now.getHours()+':'+now.getMinutes()+':'+now.getSeconds()
							list[i].createdTime = date;
						}
						if(page==1){
							this.dataList = list;
						}else{
							this.dataList = this.dataList.concat(list)
						}
						this.count = res.data.data.count;
						this.page = page;
					}else{
						uni.showToast({
							title: res.data.errmsg,
							icon:'none'
						});
					}
				})
			},
			toDetail(id){
				uni.navigateTo({
					url: `/subpack/user/balance/balance_detail?id=${id}`
				});
			},
			back(){
				// #ifdef H5
					window.history.back(-1);
				// #endif 
				// #ifndef H5
				uni.navigateBack();
				// #endif
			}
		},
		onReachBottom(){
			if(this.dataList.length<this.count){
				this.page++;
				this.getData(this.page);
			}
		},
	}
</script>

<style lang="scss" scoped>
.page{
	font-size: 26rpx;
	.content{
		padding:0 30rpx;
		.list{
			display: flex;
			align-items: center;
			padding:16rpx 0;
			border-bottom:1px solid #ECECEC;
			.left{
				width:400rpx;
			}
			.right{
				flex:1;
				
			}
		}

	}
}
</style>
